package com.xzlcPT.controller;

import com.amazonaws.services.dynamodbv2.xspec.L;
import com.sun.org.apache.xpath.internal.operations.Mod;
import com.util.MailUtil;
import com.util.PageBean;
import com.xzlcPT.bean.*;
import com.xzlcPT.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Administrator on 2017/7/6.
 */
@Controller
@RequestMapping("/Postion")
@SessionAttributes({"userLogin"})
public class PostionController extends BaseController {

    @Autowired
    private XzPostionService postionService;
    @Autowired
    private XzPostionBrowseService postionBrowseService;
    @Autowired
    private XzCompanyService companyService;
    @Autowired
    private LoginUserService loginService;
    @Autowired
    private XzPostionCollectService postionCollectService;
    @Autowired
    private XzResumeService xzResumeService;
    @Autowired
    private XzPostionSendService postionSendService;


    @InitBinder
    public void initBinder(WebDataBinder binder) {
        //日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }

    //按id删除
    @ResponseBody
    @RequestMapping("delById.do")
    public Map delById(Long postionId) {
        Map map = new HashMap();
        int i = postionService.deleteById(postionId);
        if (i > 0) {
            map.put("msg", "ok");
        } else {
            map.put("msg", "err");
        }
        return map;
    }

    //按id批量删除
    @ResponseBody
    @RequestMapping("delByIdPL.do")
    public Map delById(@RequestBody Long[] postionIds) {
        Map map = new HashMap();
        List<Long> ids = new ArrayList<>();
        for (Long postionId : postionIds) {
            ids.add(postionId);
        }
        int i = postionService.delPostionAll(ids);
        if (i > 0) {
            map.put("msg", "ok");
        } else {
            map.put("msg", "err");
        }
        return map;
    }

    //公司发布职位查询
    @ResponseBody
    @RequestMapping("/selPostionSend.do")
    public Map selPostionSend(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer rows,
                              Long companyId, String postionName, String postionSpace, String postionWelfare, Date beginDate, Date endDate) {
        Map searchMap = new HashMap();
        searchMap.put("companyId", companyId);
        searchMap.put("postionName", postionName);
        searchMap.put("postionSpace", postionSpace);
        searchMap.put("postionWelfare", postionWelfare);
        searchMap.put("beginDate", beginDate);
        searchMap.put("endDate", endDate);
        Map map = new HashMap();
        PageBean<XzPostion> pb = postionService.selPostionSendList(searchMap, page, rows);
        map.put("postionList", pb.getList());
        map.put("searchMap", searchMap);
        map.put("page", pb.getPageNum());
        map.put("pages", pb.getPages());
        map.put("total", pb.getTotal());
        map.put("size", pb.getSize());
        return map;
    }

    //职位列表查询
    @RequestMapping("/selPostionIndex.do")
    public ModelAndView selPostionIndex(@ModelAttribute("userLogin") XzLogin userLogin, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer rows,
                                        String[] fields, String salary, String fadate, String company_scale, String company_nature, String workspace, String likeStr) {
        Map map = new HashMap();
        if (workspace != null && !workspace.equals("全国")) {
            map.put("workspace", workspace);
        }
        map.put("likeStr", likeStr);
        map.put("fields", fields);
        List<String> alist = new ArrayList<>();
        if (salary != null) {
            alist.add(salary);
            String[] ss = salary.split("_");
            if (!ss[1].equals("x")) {
                map.put("salaryMin", Integer.parseInt(ss[1]));
            }
            if (!ss[2].equals("x")) {
                map.put("salaryMax", Integer.parseInt(ss[2]));
            }
        }
        if (fadate != null && !fadate.equals("")) {
            alist.add(fadate);
            map.put("fadate", Integer.parseInt(fadate.split("_")[1]));
        }
        if (company_scale != null) {
            alist.add(company_scale);
            map.put("companyScale", company_scale.split("_")[1]);
        }
        if (company_nature != null) {
            alist.add(company_nature);
            map.put("companyNature", Integer.parseInt(company_nature.split("_")[1]));
        }

        ModelAndView mv = new ModelAndView("foreEnd3/zp_gslb");
        PageBean<XzPostion> pageBean = postionService.selPostionIndex(page, rows, map);
        List<XzPostionBrowse> postionBrowses = postionBrowseService.selPostionBrowse(userLogin.getMember().getMemberId());//查询浏览记录
        List<XzCompany> companyList = companyService.selRecommend();
        mv.addObject("companyList", companyList);
        mv.addObject("postionList", pageBean.getList());
        mv.addObject("postionBrowses", postionBrowses);
        mv.addObject("page", pageBean.getPageNum());
        mv.addObject("pages", pageBean.getPages());
        mv.addObject("total", pageBean.getTotal());


        if (fields != null) {
            for (String field : fields) {
                alist.add(field);
            }
        }

        map.put("alist", alist);
        mv.addObject("queryPostion", map);
        return mv;
    }

    //类表查询异步
    @ResponseBody
    @RequestMapping("selPostionIndexAjax.do")
    public Map selPostionIndexAjax(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "6") Integer rows,
                                   String workspace, String likeStr) {
        Map map = new HashMap();
        if (workspace != null && !workspace.equals("全国")) {
            map.put("workspace", workspace);
        }
        if (likeStr != null && !likeStr.equals("")) {
            map.put("likeStr", likeStr);
        }
        PageBean<XzPostion> pageBean = postionService.selPostionIndex(page, rows, map);
        if (pageBean.getTotal() >= 10) {
            map.put("postionList", pageBean.getList());
        } else {
            Map noMap = new HashMap();
            pageBean = postionService.selPostionIndex(page, rows, noMap);
            map.put("postionList", pageBean.getList());
        }
        map.put("page", pageBean.getPageNum());
        map.put("pages", pageBean.getPages());
        return map;
    }

    //按职位id查询详情
    @RequestMapping("selPostionById.do")
    public ModelAndView selPostionById(Long postionId) {
        ModelAndView mv = new ModelAndView();
        return mv;
    }

    //职位详情
    @RequestMapping("selPostionInfo.do")
    public ModelAndView selPostionInfo(@ModelAttribute("userLogin") XzLogin userLogin, Long postionId) {
        ModelAndView mv = new ModelAndView("/foreEnd3/zp_zwxq");
        XzPostion xzPostion = postionService.selPostionInfo(postionId);
        PageBean<XzPostion> pageBean1 = postionService.selInfoByComId(1, 3, xzPostion);//该公司相似职位
        List<XzPostion> cplist = pageBean1.getList();
        PageBean<XzPostion> pageBean = postionService.selInfoByName(1, 9, xzPostion);//感兴趣的职位
        List<XzPostion> plist = pageBean.getList();
        postionBrowseService.insertPostionBrowse(postionId, userLogin.getMember().getMemberId());//职位浏览记录
        List<XzCompany> companyList = companyService.selRecommend();
        XzCompany xzCompany = companyService.selCompanyInf(xzPostion.getCompanyId());
        mv.addObject("xzCompany", xzCompany);
        mv.addObject("companyList", companyList);
        mv.addObject("cplist", cplist);
        mv.addObject("xzPostion", xzPostion);
        mv.addObject("userLogin", userLogin);
        mv.addObject("plist", plist);
        return mv;
    }

    //可能感兴趣的职位
    @ResponseBody
    @RequestMapping("selInfoByName.do")
    public Map selInfoByName(Long postionId) {
        XzPostion xzPostion = postionService.selPostionInfo(postionId);
        PageBean<XzPostion> pageBean = postionService.selInfoByName(1, 9, xzPostion);
        List<XzPostion> plist = pageBean.getList();
        Map map = new HashMap();
        map.put("plist", plist);
        return map;
    }

    //草稿箱预览
    @RequestMapping("selInfoByPostionId.do")
    public ModelAndView selInfoByPostionId(Long postionId) {
        ModelAndView mv = new ModelAndView("/foreEnd3/zpc_position_management");
        XzPostion xzPostion = postionService.selPostionInfo(postionId);
        mv.addObject("xzPostion", xzPostion);
        return mv;
    }

    //按职位名模糊查询
    @RequestMapping("selPostionByname.do")
    public ModelAndView selPostionByname(String postionName) {
        ModelAndView mv = new ModelAndView("/foreEnd3/test2");
        XzPostion xzPostion = new XzPostion();
        xzPostion.setPostionName(postionName);
        PageBean<XzPostion> pageBean = postionService.selInfoByName(1, 100, xzPostion);
        List plist = pageBean.getList();
        mv.addObject("plist", plist);
        return mv;
    }

    //添加职位信息
    @RequestMapping("insertPostion.do")
    public ModelAndView insertPostion(@ModelAttribute("userLogin") XzLogin userLogin, String postionName, String postionSpace, String postionDepartment, Integer peopleNumber,
                                      Integer postionMm, Integer postionYm, Integer publishMonth, String postionExp, String postionEducation, Integer educationEntrance,
                                      String postionDescription, String postionSpecialty, String postionAgeMin, String postionAgeMax, Integer check, Integer postionWelfare, String type) {
        ModelAndView mv = new ModelAndView("redirect:/view/foreEnd3/zpc_position_management.html");
        Map map = new HashMap();
        map.put("postionName", postionName);
        map.put("postionSpace", postionSpace);
        map.put("postionDepartment", postionDepartment);
        map.put("peopleNumber", peopleNumber);
        if (postionMm == null && postionYm == null) {
            postionMm = -1;
        }
        map.put("postionMm", postionMm);
        map.put("postionYm", postionYm);
        map.put("publishMonth", publishMonth);
        if (postionExp == null) {
            postionExp = "不限";
        }
        map.put("postionExp", postionExp);
        map.put("postionEducation", postionEducation);
        map.put("postionDescription", postionDescription);
        map.put("postionSpecialty", postionSpecialty);
        map.put("postionAgeMin", postionAgeMin);
        map.put("postionAgeMax", postionAgeMax);
        map.put("companyId", userLogin.getCompany().getCompanyId());
        map.put("educationEntrance", educationEntrance);
        map.put("postionWelfare", postionWelfare);
        Date cdate = new Date();
        if (postionWelfare == 1) {
            map.put("deleteTime", cdate);
        }
        map.put("createTime", cdate);
        map.put("publishTime", cdate);
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(cdate);
        calendar.add(calendar.MONTH, publishMonth);
        Date adate = calendar.getTime();
        map.put("overTime", adate);
        map.put("postionTime", cdate);
        if (check != null && check == 1) {
            map.put("forceAgeMax", postionAgeMax);
            map.put("forceAgeMin", postionAgeMin);
            map.put("forceSpecialty", postionSpecialty);
        }
        int i = postionService.insertPostion(map);
        mv.addObject("i", i);
        mv.addObject("type", type);
        return mv;
    }

    //审核未通过修改
    @RequestMapping("updatePostion.do")
    public ModelAndView updatePostion(@ModelAttribute("userLogin") XzLogin userLogin, String postionName, String postionSpace, String postionDepartment, Integer peopleNumber,
                                      Integer postionMm, Integer postionYm, Integer publishMonth, String postionExp, String postionEducation, Integer educationEntrance,
                                      String postionDescription, String postionSpecialty, String postionAgeMin, String postionAgeMax, Integer check, Integer postionWelfare, String type, Long postionId) {
        ModelAndView mv = new ModelAndView("redirect:/view/foreEnd3/zpc_position_management.html");
        Map map = new HashMap();
        map.put("postionId", postionId);
        map.put("postionName", postionName);
        map.put("postionSpace", postionSpace);
        map.put("postionDepartment", postionDepartment);
        map.put("peopleNumber", peopleNumber);
        if (postionMm == null && postionYm == null) {
            postionMm = -1;
        }
        map.put("postionMm", postionMm);
        map.put("postionYm", postionYm);
        map.put("publishMonth", publishMonth);
        if (postionExp == null) {
            postionExp = "不限";
        }
        map.put("postionExp", postionExp);
        map.put("postionEducation", postionEducation);
        map.put("postionDescription", postionDescription);
        map.put("postionSpecialty", postionSpecialty);
        map.put("postionAgeMin", postionAgeMin);
        map.put("postionAgeMax", postionAgeMax);
        map.put("companyId", userLogin.getCompany().getCompanyId());
        map.put("educationEntrance", educationEntrance);
        map.put("postionWelfare", postionWelfare);
        Date cdate = new Date();
        if (postionWelfare == 1) {
            map.put("deleteTime", cdate);
        }
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(cdate);
        calendar.add(calendar.MONTH, publishMonth);
        Date adate = calendar.getTime();
        map.put("overTime", adate);
        map.put("postionTime", cdate);
        if (check != null && check == 1) {
            map.put("forceAgeMax", postionAgeMax);
            map.put("forceAgeMin", postionAgeMin);
            map.put("forceSpecialty", postionSpecialty);
        }
        int i = postionService.updatePostion(map);
        mv.addObject("i", i);
        mv.addObject("type", type);
        return mv;
    }


    //修改投递状态(审核中)
    @ResponseBody
    @RequestMapping("updateStateIng.do")
    public Map updateStateIng(Long postionId) {
        XzPostion xzPostion = new XzPostion();
        xzPostion.setPostionId(postionId);
        xzPostion.setPostionWelfare("1");
        Date date = new Date();
        xzPostion.setPostionTime(date);
        int i = postionService.updateState(xzPostion);
        Map map = new HashMap();
        map.put("i", i);
        return map;
    }

    //修改投递状态同步(审核中)
    @RequestMapping("updateState_a.do")
    public ModelAndView updateState_a(XzPostion postion) {
        ModelAndView mv = new ModelAndView("redirect:/view/foreEnd3/zpc_position_management.html");
        XzPostion xzPostion = new XzPostion();
        xzPostion.setPostionId(postion.getPostionId());
        xzPostion.setPostionWelfare("1");
        Date date = new Date();
        xzPostion.setPostionTime(date);
        int i = postionService.updateState(xzPostion);
        mv.addObject("i", i);
        return mv;
    }

    //修改职位草稿同步
    @RequestMapping("updateState_b.do")
    public ModelAndView updateState_b(XzPostion postion) {
        ModelAndView mv = new ModelAndView("redirect:/view/foreEnd3/zpc_position_management.html");
        Date date = new Date();
        postion.setPublishTime(date);
        int i = postionService.updateByPrimaryKeySelective(postion);
        mv.addObject("i", i);
        return mv;
    }

    //修改投递状态(暂停发布)
    @ResponseBody
    @RequestMapping("updateStatePasue.do")
    public Map updateStatePasue(Long postionId) {
        XzPostion xzPostion = new XzPostion();
        xzPostion.setPostionId(postionId);
        xzPostion.setPostionWelfare("4");
        Date date = new Date();
        xzPostion.setPostionTime(date);
        int i = postionService.updateState(xzPostion);
        Map map = new HashMap();
        map.put("i", i);
        return map;
    }

    //修改投递状态(停止发布)
    @ResponseBody
    @RequestMapping("updateStateStop.do")
    public Map updateStateStop(Long postionId) {
        XzPostion xzPostion = new XzPostion();
        xzPostion.setPostionId(postionId);
        xzPostion.setPostionWelfare("5");
        Date date = new Date();
        xzPostion.setPostionTime(date);
        int i = postionService.updateState(xzPostion);
        Map map = new HashMap();
        map.put("i", i);
        return map;
    }

    //修改投递状态(正在招聘)
    @ResponseBody
    @RequestMapping("updateStateZping.do")
    public Map updateStateZping(Long postionId) {
        Map map = new HashMap();
        XzPostion xzPostion = new XzPostion();
        xzPostion.setPostionId(postionId);
        xzPostion.setPostionWelfare("3");
        int i = postionService.updateState(xzPostion);
        map.put("i", i);
        return map;
    }

    //按公司Id查职位
    @ResponseBody
    @RequestMapping("selByCompanyId.do")
    public Map selByCompanyId(@ModelAttribute("userLogin") XzLogin xzLogin) {
        Map map = new HashMap();
        List<XzPostion> list = postionService.selByCompanyId(xzLogin.getCompany().getCompanyId());
        map.put("list", list);
        return map;
    }

    //按ID查询职位详情
    @ResponseBody
    @RequestMapping("selectByPrimaryKey.do")
    public ModelAndView selectByPrimaryKey(Long postionId) {
        ModelAndView mv = new ModelAndView("foreEnd3/zpc_publishposition");
        XzPostion xzPostion = postionService.selectByPrimaryKey(postionId);
        mv.addObject("xzPostion", xzPostion);
        mv.addObject("ty", "change");
        return mv;
    }

    //控制发职位
    @RequestMapping("forPublish.do")
    public ModelAndView forPublish(@ModelAttribute("userLogin") XzLogin userLogin) {
        XzCompany xzCompany = companyService.selectByPrimaryKey(userLogin.getCompany().getCompanyId());
        String aa = "";
        int i = 1;
        if (xzCompany.getCompanyState() == 2) {
            aa = "/foreEnd3/zpc_publishposition";
        } else if (xzCompany.getCompanyState() == 0) {
            aa = "/foreEnd3/zpc_company_home";
            i = 1;
        } else if (xzCompany.getCompanyState() == 1) {
            aa = "/foreEnd3/zpc_company_home";
            i = 2;
        } else if (xzCompany.getCompanyState() == 3) {
            aa = "/foreEnd3/zpc_company_home";
            i = 3;
        }
        ModelAndView mv = new ModelAndView(aa);
        mv.addObject("iii", i);
        return mv;
    }

    //-------------------------------- 以下为管理员用户操作的方法-------------------------------------------

    //查询所有审核中的职位
    @RequestMapping("selectAllByWelfare.emp")
    public ModelAndView selectAllByWelfare(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
        ModelAndView mv = new ModelAndView("index");
        PageBean<XzPostion> pageBean = postionService.selectAllByWelfare(page, rows);
        List<XzPostion> list = pageBean.getList();
        mv.addObject("list", list);
        mv.addObject("page", pageBean.getPageNum());
        mv.addObject("pages", pageBean.getPages());
        mv.addObject("total", pageBean.getTotal());
        return mv;
    }

    //修改审核中的职位的状态
    @ResponseBody
    @RequestMapping("updateByWelfare.emp")
    public Map updateByWelfare(XzPostion xzPostion) {
        int i = postionService.updateByWelfare(xzPostion);
        Map map = new HashMap();
        if (i == 1) {
            map.put("msg", "ok");
        } else {
            map.put("msg", "err");
        }
        return map;
    }

    //查询所有职位
    @RequestMapping("selectAll.emp")
    public ModelAndView selectAll(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "8") Integer rows,XzPostion xzPostion) {
        ModelAndView mv = new ModelAndView("backEnd3/postion_manage");
        PageBean<XzPostion> pageBean = postionService.selectAll_emp(page, rows,xzPostion);
        mv.addObject("postionList", pageBean.getList());
        mv.addObject("page", pageBean.getPageNum());
        mv.addObject("pages", pageBean.getPages());
        mv.addObject("total", pageBean.getTotal());
        mv.addObject("postionWelfare", xzPostion.getPostionWelfare());
        return mv;
    }

    //查看职位详情
    @RequestMapping("selectByPrimaryKey1.emp")
    public ModelAndView selectByPrimaryKey1(Long postionId) {
        ModelAndView mv = new ModelAndView("backEnd3/postion_revise");
        XzPostion xzPostion = postionService.selectByPrimaryKey(postionId);
        mv.addObject("xzPostion", xzPostion);
        return mv;
    }

    //修改职位详情（查看）
    @RequestMapping("selectByPrimaryKey2.emp")
    public ModelAndView selectByPrimaryKey2(Long postionId) {
        ModelAndView mv = new ModelAndView("backEnd3/postion_update");
        XzPostion xzPostion = postionService.selectByPrimaryKey(postionId);
        mv.addObject("xzPostion", xzPostion);
        return mv;
    }

    //修改职位信息
    @RequestMapping("updateByPrimaryKeySelective.emp")
    public ModelAndView updateByPrimaryKeySelective(XzPostion xzPostion) {
        ModelAndView mv = new ModelAndView("backEnd3/postion_revise");
        int i = postionService.updateByPrimaryKeySelective(xzPostion);
        mv.addObject("i", i);
        return mv;
    }

    //通过审核
    @ResponseBody
    @RequestMapping("adoptPostion.emp")
    public Map adoptPostion(Long postionId) {
        Map map = new HashMap();
        XzPostion xzPostion = new XzPostion();
        xzPostion.setPostionId(postionId);
        xzPostion.setPostionWelfare("3");
        Date date = new Date();
        xzPostion.setPostionTime(date);
        int i = postionService.adoptPostion(xzPostion);
        if (i == 1) {
            map.put("msg", "ok");
        } else {
            map.put("msg", "err");
        }
        return map;
    }

    //未通过审核
    @ResponseBody
    @RequestMapping("upPostion.emp")
    public Map upPostion(@ModelAttribute("adminLogin") XzLogin xzLogin, String msgContent, Long companyId, String postionName, Long postionId) {
        Map map = new HashMap();
        XzPostion xzPostion = new XzPostion();
        xzPostion.setPostionId(postionId);
        xzPostion.setCompanyId(companyId);
        xzPostion.setPostionName(postionName);
        xzPostion.setFiled1(msgContent);
        xzPostion.setPostionWelfare("2");
        Date date = new Date();
        xzPostion.setPostionTime(date);
        int i = postionService.upPostion(xzPostion, xzLogin);
        if (i == 1) {
            map.put("msg", "ok");
        } else {
            map.put("msg", "err");
        }
        return map;
    }

    //查看是否通过审核
    @ResponseBody
    @RequestMapping("selAdopt.emp")
    public Map selAdopt(Long postionId) {
        Map map = new HashMap();
        int i = postionService.selAdopt(postionId);
        if (i == 1) {
            map.put("msg", "ok");
        } else {
            map.put("msg", "err");
        }
        return map;
    }

    //---------------------------移动端---------------------------
    @ResponseBody
    @RequestMapping("selPostion.go")
    public Map selPostionGO(String likeStr, String workspace, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "6") Integer rows) {
        Map smap = new HashMap();
        if (workspace != null && !workspace.equals("全国")) {
            smap.put("workspace", workspace);
        }
        smap.put("likeStr", likeStr);
        PageBean<XzPostion> pageBean = postionService.selPostionIndexx(page, rows, smap);
        Map map = new HashMap();
        map.put("postionList", pageBean.getList());
        map.put("page", pageBean.getPageNum());
        map.put("pages", pageBean.getPages());
        map.put("rows", pageBean.getPageSize());
        map.put("total", pageBean.getTotal());
        return map;
    }

    @ResponseBody
    @RequestMapping("selPosMob.go")
    public Map selPosMob(@RequestBody Map aa) {
        String likeStr = String.valueOf(aa.get("likeStr"));
        String workspace = String.valueOf(aa.get("workspace"));
        String salary = String.valueOf(aa.get("salary"));
        String fadate = String.valueOf(aa.get("fadate"));
        int page = Integer.parseInt(String.valueOf(aa.get("page")));
        int rows = 3;
        Map map = new HashMap();
        if (workspace != null && !workspace.equals("全国")) {
            map.put("workspace", workspace);
        }
        map.put("likeStr", likeStr);
        ArrayList a = (ArrayList) aa.get("fields");
        if (a != null) {
            String[] fields = new String[a.size()];
            for (int i = 0; i < a.size(); i++) {
                fields[i] = String.valueOf(a.get(i));
            }
            map.put("fields", fields);
        }
        List<String> alist = new ArrayList<>();
        if (salary != null && salary != "" && salary != "null") {
            alist.add(salary);
            String[] ss = salary.split("_");
            if (!ss[1].equals("x")) {
                map.put("salaryMin", Integer.parseInt(ss[1]));
            }
            if (!ss[2].equals("x")) {
                map.put("salaryMax", Integer.parseInt(ss[2]));
            }
        }
        if (fadate != null && !fadate.equals("") && fadate != "null") {
            alist.add(fadate);
            map.put("fadate", Integer.parseInt(fadate.split("_")[1]));
        }
        PageBean<XzPostion> pageBean = postionService.selPostionIndexx(page, rows, map);
        Map map1 = new HashMap();
        map1.put("postionList", pageBean.getList());
        map1.put("page", pageBean.getPageNum());
        map1.put("pages", pageBean.getPages());
        map1.put("rows", pageBean.getPageSize());
        map1.put("total", pageBean.getTotal());
        return map1;
    }

    //查询浏览记录
    @ResponseBody
    @RequestMapping("selPostionBrowse.go")
    public Map selPostionBrowse(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer rows, @RequestHeader("accessToken") String token) {
        Map map = new HashMap();
        XzLogin xzLogin = loginService.selByToken(token);
        PageBean<XzPostionBrowse> pageBean = postionBrowseService.selPostionBrowse(page, rows, xzLogin.getMember().getMemberId());//查询浏览记录
        map.put("postionBrowseList", pageBean.getList());
        map.put("page", pageBean.getPageNum());
        map.put("pages", pageBean.getPages());
        map.put("rows", pageBean.getPageSize());
        map.put("total", pageBean.getTotal());
        return map;
    }

    //职位详情
    @ResponseBody
    @RequestMapping("selPostionInfoMob.go")
    public Map selPostionInfoMob(Long postionId, @RequestHeader("accessToken") String token, String msg, String insertSelectivemsg) {
        XzLogin xzLogin = loginService.selByToken(token);
        XzResume resume = xzResumeService.selectByMemberId(xzLogin.getMember().getMemberId());
        XzPostion xzPostion = postionService.selPostionInfo(postionId);
        Map map1 = new HashMap();
        map1.put("memberId", xzLogin.getMember().getMemberId());
        map1.put("postionId", postionId);
        int i = postionCollectService.selCollectState(map1);
        Map map2 = new HashMap();
        map2.put("resumeId", resume.getResumeId());
        map2.put("postionId", postionId);
        int j = postionSendService.selisSend(map2);
        Map map = new HashMap();
        if (j > 0) {
            map.put("selisSend", "ok");
        } else {
            map.put("selisSend", "err");
        }
        if (i == 1) {
            map.put("CollectState", "ok");
        } else {
            map.put("CollectState", "err");
        }
        if (msg != "") {
            map.put("msg", msg);
        }
        if (insertSelectivemsg != "") {
            map.put("insertSelectivemsg", insertSelectivemsg);
        }
        map.put("xzPostion", xzPostion);
        return map;
    }

    //我感兴趣的职位
    @ResponseBody
    @RequestMapping("selInfoByNameMob.go")
    public Map selInfoByNameMob(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "3") Integer rows, Long postionId) {
        Map<String, Object> map = new HashMap<>();
        XzPostion xzPostion = postionService.selPostionInfo(postionId);
        PageBean<XzPostion> pageBean = postionService.selInfoByNameMob(page, rows, xzPostion);//感兴趣的职位
        List<XzPostion> plist = pageBean.getList();
        map.put("plist", plist);
        map.put("page", pageBean.getPageNum());
        map.put("pages", pageBean.getPages());
        map.put("rows", pageBean.getPageSize());
        map.put("total", pageBean.getTotal());
        return map;
    }

    //按公司Id查职位
    @ResponseBody
    @RequestMapping("selByCompanyIdMob.go")
    public Map selByCompanyIdMob(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "3") Integer rows, Long companyId) {
        Map map = new HashMap();
        PageBean<XzPostion> pageBean = postionService.selByCompanyIdMob(page, rows, companyId);
        map.put("list", pageBean.getList());
        map.put("page", pageBean.getPageNum());
        map.put("pages", pageBean.getPages());
        map.put("rows", pageBean.getPageSize());
        map.put("total", pageBean.getTotal());
        return map;
    }

    //收藏职位
    @RequestMapping("insertCollectMob.go")
    public ModelAndView insertCollectMob(Long postionId, @RequestHeader("accessToken") String token) {
        ModelAndView mv = new ModelAndView("forward:selPostionInfoMob.go");
        Date collectTime = new Date();
        Map map = new HashMap();
        XzLogin xzLogin = loginService.selByToken(token);
        map.put("postionId", postionId);
        map.put("memberId", xzLogin.getMember().getMemberId());
        map.put("collectTime", collectTime);
        int i = postionService.insertCollect(map);
        if (i == 1) {
            mv.addObject("msg", "ok");
        } else {
            mv.addObject("msg", "err");
        }
        return mv;
    }

    //删除收藏
    @RequestMapping("deleteCollectMob.go")
    public ModelAndView deleteCollectMob(Long postionId, @RequestHeader("accessToken") String token) {
        ModelAndView mv = new ModelAndView("forward:selPostionInfoMob.go");
        XzLogin xzLogin = loginService.selByToken(token);
        Map map = new HashMap();
        map.put("postionId", postionId);
        map.put("memberId", xzLogin.getMember().getMemberId());
        int i = postionService.deleteCollectMob(map);
        if (i == 1) {
            mv.addObject("msg", "ok");
        } else {
            mv.addObject("msg", "err");
        }
        return mv;
    }

    //简历投递
    @RequestMapping("sendPostionMob.go")
    public ModelAndView sendPostionMob(Long postionId, @RequestHeader("accessToken") String token) {
        ModelAndView mv = new ModelAndView("forward:selPostionInfoMob.go");
        XzLogin xzLogin = loginService.selByToken(token);
        XzResume resume = xzResumeService.selectByMemberId(xzLogin.getMember().getMemberId());
        XzPostion postion = postionService.selPostionInfo(postionId);
        Long companyId = postion.getCompanyId();
        Long resumeId = resume.getResumeId();
        Date date = new Date();
        XzPostionSend xzPostionSend = new XzPostionSend();
        xzPostionSend.setResumeId(resumeId);
        xzPostionSend.setPostionId(postionId);
        xzPostionSend.setCompanyId(companyId);
        xzPostionSend.setSendTime(date);
        xzPostionSend.setCreateTime(date);
        xzPostionSend.setSendTime1(date);
        int i = postionSendService.insertSelective2(xzPostionSend, xzLogin);
        if (i == 1) {
            mv.addObject("insertSelectivemsg", "ok");
        } else {
            mv.addObject("insertSelectivemsg", "err");
        }
        return mv;
    }


    //职位列表查询
    @ResponseBody
    @RequestMapping("selPostionIndexMob.go")
    public Map selPostionIndexMob(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5") Integer rows, String[] field) {
        Map map = new HashMap();
        map.put("fields", field);
        PageBean<XzPostion> pageBean = postionService.selPostionIndex(page, rows, map);
        Map map1 = new HashMap();
        map1.put("postionList", pageBean.getList());
        map1.put("page", pageBean.getPageNum());
        map1.put("pages", pageBean.getPages());
        map1.put("total", pageBean.getTotal());
        return map1;
    }

    //公司-------------------------------------------------------------------------------------------------------

    //公司发布职位查询(正在招聘和结束)
    @ResponseBody
    @RequestMapping("/selPostionSendMob.go")
    public Map selPostionSendMob(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5") Integer rows, @RequestHeader("accessToken") String token) {
        // ,String postionName,String postionSpace,String postionWelfare,Date beginDate,Date endDate
//        Map searchMap = new HashMap();
//        searchMap.put("companyId",companyId);
//        searchMap.put("postionName",postionName);
//        searchMap.put("postionSpace",postionSpace);
//        searchMap.put("postionWelfare",postionWelfare);
//        searchMap.put("beginDate",beginDate);
//        searchMap.put("endDate",endDate);

        XzLogin xzLogin = loginService.selByToken(token);
        Map map = new HashMap();
        PageBean<XzPostion> pb = postionService.selPostionSendListMob(xzLogin.getCompany().getCompanyId(), page, rows);
        map.put("postionList", pb.getList());
//        map.put("searchMap",searchMap);
        map.put("page", pb.getPageNum());
        map.put("pages", pb.getPages());
        map.put("total", pb.getTotal());
        map.put("size", pb.getSize());
        return map;
    }

    //控制发职位
    @ResponseBody
    @RequestMapping("forPublishMob.go")
    public Map forPublishMob(@RequestHeader("accessToken") String token) {
        Map map = new HashMap();
        XzLogin xzLogin = loginService.selByToken(token);
        XzCompany xzCompany = companyService.selectByPrimaryKey(xzLogin.getCompany().getCompanyId());
        int i = 1;
        if (xzCompany.getCompanyState() == 2) {
            i = 2;
        } else if (xzCompany.getCompanyState() == 0) {
            i = 0;
        } else if (xzCompany.getCompanyState() == 1) {
            i = 1;
        } else if (xzCompany.getCompanyState() == 3) {
            i = 3;
        }
        XzPostion xzPostion = new XzPostion();
        xzPostion.setCompanyId(xzCompany.getCompanyId());
        map.put("state", i);
        map.put("xzPostion", xzPostion);
        return map;
    }

    //添加职位信息
    @ResponseBody
    @RequestMapping("insertPostionMob.go")
    public Map insertPostionMob(XzPostion xzPostion) {
        Map map = new HashMap();
        map.put("postionName", xzPostion.getPostionName());
        map.put("postionSpace", xzPostion.getPostionSpace());
        map.put("postionAgeMin", "");
        map.put("postionAgeMax", "");
        if (xzPostion.getPostionMm() == null && xzPostion.getPostionYm() == null) {
            xzPostion.setPostionMm(-1);
        }
        map.put("postionMm", xzPostion.getPostionMm());
        map.put("postionYm", xzPostion.getPostionYm());
        if (xzPostion.getPostionExp() == null) {
            xzPostion.setPostionExp("不限");
        }
        map.put("postionExp", xzPostion.getPostionExp());
        map.put("postionEducation", xzPostion.getPostionEducation());
        map.put("postionDescription", xzPostion.getPostionDescription());
        map.put("companyId", xzPostion.getCompanyId());
        map.put("postionWelfare", xzPostion.getPostionWelfare());
        Date cdate = new Date();
        map.put("createTime", cdate);
        map.put("publishTime", cdate);
        map.put("postionTime", cdate);
        int i = postionService.insertPostion(map);
        if (i > 0) {
            map.put("msg", "ok");
        } else {
            map.put("msg", "发布职位失败");
        }
        return map;
    }

    //公司职位详情
    @ResponseBody
    @RequestMapping("selPosComMob.go")
    public Map selPosComMob(Long postionId) {
        Map map = new HashMap();
//        XzLogin xzLogin = loginService.selByToken(token);
        XzPostion xzPostion = postionService.selPostionInfo(postionId);
        map.put("xzPostion", xzPostion);
        return map;
    }

    //修改投递状态
    @ResponseBody
    @RequestMapping("updateStatePasueMob.go")
    public Map updateStatePasueMob(Long postionId, int postionWelfare) {
        XzPostion xzPostion = new XzPostion();
        xzPostion.setPostionId(postionId);
        xzPostion.setPostionWelfare(postionWelfare + "");
        Date date = new Date();
        xzPostion.setPostionTime(date);
        int i = postionService.updateState(xzPostion);
        Map map = new HashMap();
        if (i > 0) {
            map.put("statemsg", "ok");
        }
        return map;
    }

    //20171226-王继顺
    //职位浏览
    @ResponseBody
    @RequestMapping("selPosBrowseMob.go")
    public Map SelPosBrowse(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5") Integer rows, Long postionId) {
        PageBean<XzPostionBrowse> pb = postionBrowseService.selPosBrowByPosId(page, rows, postionId);
        List<XzResume> resumeList = new ArrayList<>();
        for (XzPostionBrowse browse : pb.getList()) {
            resumeList.add(xzResumeService.selectByMemberId(browse.getMemberId()));
        }
        Map<String, Object> map = new HashMap<>();
        map.put("resumeList", resumeList);
        map.put("page", pb.getPageNum());
        map.put("pages", pb.getPages());
        map.put("total", pb.getTotal());
        map.put("postionId", postionId);
        return map;
    }

    //20171226-王继顺
    //职位浏览人数
    @ResponseBody
    @RequestMapping("selPosBrowseNum.go")
    public Map SelPosBrowseNum(Long postionId) {
        int count = postionBrowseService.selectCountByPostionId(postionId);
        Map<String, Object> map = new HashMap<>();
        map.put("count", count);
        return map;
    }

    //20180102-王继顺
    //移动端 企业 职位管理 删除职位 按id删除
    @ResponseBody
    @RequestMapping("delById.go")
    public Map delByIdMob(Long postionId) {
        Map<String, String> map = new HashMap<>();
        int i = postionService.deleteById(postionId);
        if (i > 0) {
            map.put("msg", "ok");
        } else {
            map.put("msg", "err");
        }
        return map;
    }


}
